-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[DataGrid] Fix tree data unable to deselect row for exclude model #19846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Deploy preview: https://deploy-preview-19846--material-ui-x.netlify.app/ Bundle size report
|
MBilalShafi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still have some bleeding edges around the exclude model with nested data (unrelated to this specific issue) like https://stackblitz.com/edit/axg8fqmk-ex2nb3fw
I will try to refactor the row selection logic to adapt it better to both the types.
What's the issue? Could you link to a Github issue? |
I think we don't have one yet. I'll recheck and create one. |
@MBilalShafi did you already create an issue for this? |
Not yet. I was testing a few different issues around this problem to add more context to it. |
Fixes #19046
Before: https://stackblitz.com/edit/axg8fqmk?file=src%2FDemo.tsx
After: https://stackblitz.com/edit/54tkqjct?file=src%2FDemo.tsx
The Bug
When using a controlled exclude model with tree data and row selection propagation, the grid corrupts the model by treating excluded row IDs as selected row IDs.
Step-by-Step Bug Flow
1. User provides controlled exclude model
Meaning: "All rows selected EXCEPT row 1 (Thomas)"
2. Grid calls
getPropagatedRowSelectionModelWhen the controlled prop is provided,
syncControlledState(line 849) calls:3. Bug: Function treats excluded IDs as selected IDs
Before Fix (lines 436-466):
4. What happens inside the propagation
Tree structure:
Propagation flow:
findRowsToSelectis called withid = 1(Thomas - an EXCLUDED row)[2, 3, 4]selectionManager.select(childId)What
select()does for exclude models:5. The corruption
Starting model:
After propagation:
What happened:
select()was called on its children (2, 3, 4)findRowsToSelecton them!The Root Cause
Semantic mismatch:
findRowsToSelectis designed for SELECTION propagationfindRowsToSelecton unselected rows and usingselect()to "propagate" them corrupts the modelWhy exclude models don't need propagation:
When a user actually deselects a row via UI interaction, propagation ALREADY happens correctly:
Result after UI deselection:
The model is semantically complete - no "propagation reapplication" needed.
The Solution
Skip propagation for exclude models in
getPropagatedRowSelectionModelLocation:
useGridRowSelection.ts:440Change:
Test
Added a test to ensure that the exclude model is unchanged when getting from
getPropagatedRowSelectionModel